package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.indexLineVo;
import com.ruoyi.system.service.IMaterialService;
import com.ruoyi.system.service.IOrderManageService;
import com.ruoyi.system.service.IProfitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName IndexController
 * @Description 首页数据展示接口
 * @Author zlh
 * @Date 2023/4/6 15:03
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/index")
public class IndexController {
    @Autowired
    private IOrderManageService orderManageService;

    @Autowired
    private IProfitService profitService;

    @Autowired
    private IMaterialService materialService;
    /**
     * 获取现场订单总量
     */
    @GetMapping("/getOrderCount")
    public AjaxResult getOrderCount(){
        int orderCount = orderManageService.getOrderCount();
        return AjaxResult.success(orderCount);
    }
    /**
     * 计算当月利润
     */
    @GetMapping("/profitCount")
    public AjaxResult getProfit(){
        Double profitCount = Double.parseDouble(profitService.getProfitCount());
        if (profitCount != null){
            return AjaxResult.success(profitCount);
        }
        return AjaxResult.error("当前利润值为空！");
    }
    /**
     * 计算当月存量
     */
    @GetMapping("/getAllowance")
    public AjaxResult getAllowance(){
        Double allowance = profitService.getAllowance();
        if (allowance != null){
            return AjaxResult.success(allowance);
        }
        return AjaxResult.error("无法计算当月存量");
    }
    /**
     * 当月总的出货量
     */
    @GetMapping("/getShipping")
    public AjaxResult getShipping(){
        int shipping = profitService.getShipping();
        if (shipping != 0){
            return AjaxResult.success(shipping);
        }
        return AjaxResult.error("当月暂无法计算");
    }

    // 查询过去一周每天的订货量和出货量折线图
    @GetMapping("/getLastWeekOrderAndAccomplishment")
    public AjaxResult getLastWeekOrderAndAccomplishment(){
        indexLineVo indexLineVo = orderManageService.OrderCountByDay();
        if (indexLineVo != null){
            return AjaxResult.success(indexLineVo);
        }
        return AjaxResult.error("获取过去一周的数据出错");
    }
}
